import cv2
import math
import numpy as np
import random

# 读取图片
image_path = "images2/Img_0.png"
target = cv2.imread(image_path)

temp = target.copy()
# 识别纯白像素（RGB 约为 (0,0,0)）
# lower_bound = np.array([250, 250, 250])  # 设置最小白色范围
# upper_bound = np.array([255, 255, 255])  # 设置最大白色范围
# black_pixels = cv2.inRange(temp, lower_bound, upper_bound)  # 使用inRange进行范围匹配

black_pixels = np.all(temp == [255, 255, 255], axis=-1)
# 将纯白像素替换为纯黑
# temp[black_pixels] = [0, 0, 0]
# black_pixels = np.all(temp == [254, 254, 254], axis=-1)
# 将纯白像素替换为纯黑
temp[black_pixels] = [0, 0, 0]
cv2.imshow("xxxx",temp)
cv2.waitKey()
cv2.destroyAllWindows()
